package com.cqie.teacherserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cqie.campuscommon.result.Result;
import com.cqie.teacherserver.entity.TeacherReportIndex;
import com.cqie.teacherserver.entity.vo.TeacherBaseVO;
import com.cqie.teacherserver.entity.vo.TeacherCourseVO;
import com.cqie.teacherserver.mapper.TeacherReportIndexMapper;
import com.cqie.teacherserver.service.ITeacherReportIndexService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 老师报告指标 服务实现类
 * </p>
 *
 * @author zhangr132
 * @since 2024-05-31
 */
@Slf4j
@Service
public class TeacherReportIndexServiceImpl extends ServiceImpl<TeacherReportIndexMapper, TeacherReportIndex> implements ITeacherReportIndexService {

    /**
     * 教师入职时间获取
     * @param teacherCode
     * @return
     */
    @Override
    public Result getTeacherEntryTime(String teacherCode) {
        log.info("正在处理获取教师入职时间请求");
        TeacherReportIndex teacherReportIndex = getTeacherReportIndex(teacherCode);
        if (teacherReportIndex!= null) {
            log.info("教师入职时间："+teacherReportIndex.getHireDate());
            return Result.Success(teacherReportIndex.getHireDate());
        }
        log.error("未找到该教师的入职时间");
        return Result.Failed("未找到该教师的入职时间","——");
    }

    /**
     * 教师档案信息获取
     * @param teacherCode
     * @return
     */
    @Override
    public Result getTeacherDepartment(String teacherCode) {
        log.info("正在处理教师档案信息获取请求");

        TeacherReportIndex teacherReportIndex = getTeacherReportIndex(teacherCode);
        if (teacherReportIndex!= null) {
            log.info("教师所在部门："+teacherReportIndex.getDepartment());
            return Result.Success(teacherReportIndex.getDepartment());
        }
        log.error("未找到该教师的所在部门");
        return Result.Failed("未找到该教师的所在部门","——");
    }

    /**
     * 教师课程信息获取（未完成）
     * @param teacherCode
     * @return
     */
    @Override
    public Result getTeacherCourse(String teacherCode) {
        log.info("正在处理教师课程信息获取请求");
        TeacherReportIndex teacherReportIndex = getTeacherReportIndex(teacherCode);
        if (teacherReportIndex != null) {
            TeacherCourseVO teacherCourseVO = new TeacherCourseVO();
            //复制属性 teacherReportIndex -> teacherCourseVO
            BeanUtils.copyProperties(teacherReportIndex,teacherCourseVO);
            log.info("教师课程信息："+teacherCourseVO);
            return Result.Success(teacherCourseVO);
        }
        log.error("未找到该教师的课程信息");
        return Result.Failed("未找到该教师的课程信息","——");

    }

    @Override
    public Result addTeacherBaseInfo(String teacherCode) {
        log.info("正在处理教师基础信息添加请求");
        return null;
    }

    @Override
    public Result getTeacherInfo(String teacherCode) {
        log.info("正在处理教师基础信息获取请求");

        TeacherReportIndex teacherReportIndex = getTeacherReportIndex(teacherCode);
        if (teacherReportIndex!= null){
            TeacherBaseVO teacherBaseVO = new TeacherBaseVO();
            BeanUtils.copyProperties(teacherReportIndex,teacherBaseVO);
            log.info("教师基础信息："+teacherBaseVO);
            return Result.Success(teacherBaseVO);
        }
        log.error("未找到该教师的基础信息");
        return Result.Failed("未找到该教师的基础信息","——");
    }


    /**
     * 封装方法
     * 获取教师报告指标信息
     * @param teacherCode
     * @return
     */
    private TeacherReportIndex getTeacherReportIndex(String teacherCode) {
        QueryWrapper<TeacherReportIndex> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(TeacherReportIndex::getTeacherCode, teacherCode);
        TeacherReportIndex teacherReportIndex = this.getOne(queryWrapper);
        return teacherReportIndex;
    }
}
